package com.common.rest.error;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ServerErrorMapper implements ExceptionMapper<Throwable> {

	private Logger log = LoggerFactory.getLogger(ServerErrorMapper.class); 
	
	@Override
	public Response toResponse(Throwable exception) {
		log.error(exception.getMessage(), exception);
		return Response.status(Status.INTERNAL_SERVER_ERROR)
				.entity("Internal Server Error. Please contact System Admin")
				.type(MediaType.TEXT_PLAIN)
				.build();
	}

}
